﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace UM_SERVER.Packet.InPacket
{
    /// <summary>
    ///      更改用户上线状态请求包
    /// </summary>
    class ChanageUserOnlineStatePacket : BaseInPackage
    {
        public ChanageUserOnlineStatePacket(InPackage inpackage) : base(inpackage)
        {

        }

        public override void InitPackage()
        {
            int Offset = 0;
            //用户名长度
            byte[] UsernameLength = new byte[4];
            Array.ConstrainedCopy(this.Body["HEAD"], Offset, UsernameLength, 0, 4);
            Offset += 4;
            //用户名
            byte[] Username = new byte[BitConverter.ToInt32(UsernameLength, 0)];
            Array.ConstrainedCopy(this.Body["HEAD"], Offset, Username, 0, Username.Length);
            Offset += Username.Length;
            //上线状态
            byte[] OnlineState = new byte[4];
            Array.ConstrainedCopy(this.Body["HEAD"], Offset, OnlineState, 0, 4);
            Offset += 6;
            //IP地址长度
            byte[] IPLength = new byte[4];
            Array.ConstrainedCopy(this.Body["HEAD"], Offset, IPLength, 0, 4);
            Offset += 4;
            //IP地址
            byte[] IPAddress = new byte[BitConverter.ToInt32(IPLength, 0)];
            Array.ConstrainedCopy(this.Body["HEAD"], Offset, IPAddress, 0, IPAddress.Length);
            Offset += IPAddress.Length;
            //聊天端口
            byte[] TalkPort = new byte[4];
            Array.ConstrainedCopy(this.Body["HEAD"], Offset, TalkPort, 0, 4);

            this.DIC_CONTENT.Add("USERNAME", Username);
            this.DIC_CONTENT.Add("ONLINESTATE", OnlineState);
            this.DIC_CONTENT.Add("IPADDRESS", IPAddress);
            this.DIC_CONTENT.Add("TALKPORT", TalkPort);
        }

        /// <summary>
        ///      得到用户更新的上线状态
        /// </summary>
        /// <returns>返回更新的上线状态</returns>
       public UM_SERVER.Packet.InPacket.LoginPacket.LoginState GetUserOnlineState()
       {
           return (UM_SERVER.Packet.InPacket.LoginPacket.LoginState)BitConverter.ToInt32(this.DIC_CONTENT["ONLINESTATE"], 0);
       }
    }
}
